package com.fujica.invoicing.utils;

import static com.fujica.invoicing.config.StatusConfig.*;

/**
 * @ClassName ResultBody
 * @Description TODO   统一返回数据类
 * @Author admin
 * @Date 2020/8/11 15:14
 * @Version 1.0
 **/
public class ResultBody {

    /**
     * 获取正确的数据返回
     * @param object
     * @return
     */
    public static Result ok(Object object) {
        Result result = new Result();
        result.setCode(OK.getStatusCode());
        result.setMsg("请求成功");
        result.setData(object);
        return result;
    }

    /**
     * 无需返回数据
     * @return
     */
    public static Result ok() {
        return ok(null);
    }

    /**
     * 请求语法错误
     * @param msg
     * @return
     */
    public static Result badReq(String msg) {
        Result result = new Result();
        result.setCode(GRAMMAR_ERROR.getStatusCode());
        result.setMsg(msg);
        return result;
    }

    /**
     * 出现错误
     * @param code
     * @param msg
     * @return
     */
    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
